// pages/find/find.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'asda',
    context:'sdasdasdavas',
    information:["你好","深爱的","但撒上"], //数据库中的列表
    ans:[],
    nowid:1000,
    openid:"1",

    information1:{
      user_image:"../../../images/def.png",
      openid:"",
      title:"张鑫我儿子",
      date:"22.6.1",
      poster_name:"zhx",
      context:"你就是歌姬吧！",
      image:"../../../images/bgpic.png",
      tag:"娱乐",
      views:"666",
      likes:"233",
      is_liked:true,
      comment_user:[
        {
          is_open:false,
          openid:"",
          user_image:"../../../images/def.png",
          user_name:"评论用户1",
          comment_context:"评论1",
          date:"date1",
          comment_list:[
            {
              comment_id:"",
              comment_image:"",
              comment_name:"name1",
              response_to:"",
              context:"comment111",
              date:""
            },
            {
              comment_id:"",
              comment_image:"",
              comment_name:"name2",
              response_to:"",
              context:"comment2",
              date:""
            },
            {
              comment_id:"",
              comment_image:"",
              comment_name:"name3",
              response_to:"",
              context:"comment3",
              date:""
            },
            {
              comment_id:"",
              comment_image:"",
              comment_name:"name4",
              response_to:"",
              context:"comment4",
              date:""
            },
          ]
        },{
          is_open:false,
          openid:"",
          user_image:"../../../images/emoij32x32.png",
          user_name:"22222",
          comment_context:"评论2",
          date:"date2"
        },{
          is_open:false,
          openid:"",
          user_image:"../../../images/guangchang.png",
          user_name:"33333",
          comment_context:"评论3",
          date:"date3"
        }],
      
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.cloud.init({
      env:'word2-1g00kpc66ccecd65',
      traceUser:true
    })
    
    
    console.log("sad",options.title)
    this.setData({
      title : options.title,
      context : options.context,
      //openid : options.openid,
      information : this.data.information1
    })
    // const db = wx.cloud.database()
    // var that = this
    // console.log(that.data.openid)
    // var id = that.data.openid
    // // 查询当前用户所有的 counters
    // db.collection('posts').where({
    //   openid: that.data.openid
    // }).get({
    //   success: res => {
    //     that.setData({
    //       title:res.data[0].name
    //     })
    //     console.log(that.data.title)
    //     console.log('[数据库] [查询记录] 成功: ', res)
    //   },
    //   fail: err => {
    //     wx.showToast({
    //       icon: 'none',
    //       title: '查询记录失败'
    //     })
    //     console.error('[数据库] [查询记录] 失败：', err)
    //   }
    // })
  },

  //展示多级回复
  showans: function (event) {
    console.log(event.currentTarget.id)
    this.data.information1.comment_user[event.currentTarget.id].is_open=true;
    this.setData({
      nowid:event.currentTarget.id,
      ans:['多级评论1','多级评论2','多级评论3'],
      comment_user:this.data.information1.comment_user
    })
    
  },

  closeans:function(event){
    console.log(event.currentTarget.id)
    this.data.information1.comment_user[event.currentTarget.id].is_open=false;
    this.setData({
      comment_user:this.data.information1.comment_user
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})